﻿<Window x:Name="window" x:Class="DataInterpolator.View.DatabaseWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:clr="clr-namespace:System;assembly=mscorlib"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      xmlns:comvm="clr-namespace:Common.ViewModel;assembly=Common"
      xmlns:comutil="clr-namespace:Common.Utility;assembly=Common"
      xmlns:ignore="http://www.galasoft.ch/ignore"
      xmlns:p="clr-namespace:DataInterpolator.Properties"
      xmlns:view="clr-namespace:DataInterpolator.View" mc:Ignorable="d ignore"
      Height="{Binding Source={x:Static p:Settings.Default}, Path=DatabaseWindowSize.Height, Mode=TwoWay}"
      Width="{Binding Source={x:Static p:Settings.Default}, Path=DatabaseWindowSize.Width, Mode=TwoWay}"
      Left="{Binding Source={x:Static p:Settings.Default}, Path=DatabaseWindowSize.Left, Mode=TwoWay}"
      Top="{Binding Source={x:Static p:Settings.Default}, Path=DatabaseWindowSize.Top, Mode=TwoWay}"
      Title="Database Viewer"
      DataContext="{Binding Database, Source={StaticResource Locator}}">
   <Window.Resources>
      <comvm:WellBaseComparer x:Key="WellComparer" />
      <clr:String x:Key="DatumString">DATUM</clr:String>
      <clr:String x:Key="VelocityString">VELOCITY</clr:String>
   </Window.Resources>
   <Window.InputBindings>
      <KeyBinding Key="N" Modifiers="Control"
            Command="{Binding NewDatabaseCommand, Mode=OneWay}" />
      <KeyBinding Key="O" Modifiers="Control"
            Command="{Binding LoadDatabaseCommand, Mode=OneWay}" />
      <KeyBinding Key="R" Modifiers="Control"
            Command="{Binding RemoveLogsCommand, Mode=OneWay}" />
      <KeyBinding Key="S" Modifiers="Control"
            Command="{Binding SaveDatabaseCommand, Mode=OneWay}" />
      <KeyBinding Key="I" Modifiers="Control"
            Command="{Binding ImportLogsCommand, Mode=OneWay}" />

   </Window.InputBindings>
   <DockPanel HorizontalAlignment="Stretch" Height="Auto" LastChildFill="True"
         Grid.RowSpan="2" VerticalAlignment="Stretch" Width="Auto">
      <Menu Grid.RowSpan="2" VerticalAlignment="Top" DockPanel.Dock="Top">
         <MenuItem Header="File">
            <MenuItem Header="New Database"
                  Command="{Binding NewDatabaseCommand, Mode=OneWay}"
                  InputGestureText="Ctrl+N" />
            <MenuItem Header="Open Database"
                  Command="{Binding LoadDatabaseCommand, Mode=OneWay}"
                  InputGestureText="Ctrl+O" />
            <Separator />
            <MenuItem Header="Save Database"
                  Command="{Binding SaveDatabaseCommand, Mode=OneWay}"
                  InputGestureText="Ctrl+S" />
            <MenuItem Header="Save Database As..."
                  Command="{Binding SaveDatabaseAsCommand, Mode=OneWay}" />
            <Separator />
            <MenuItem Header="Import Logs..." InputGestureText="Ctrl+I"
                  Command="{Binding ImportLogsCommand, Mode=OneWay}" />
            <MenuItem Header="Remove Selected"
                  Command="{Binding RemoveLogsCommand, Mode=OneWay}"
                  InputGestureText="Ctrl+R" />

            <Separator />
            <MenuItem Header="Close" Command="{Binding CloseWindowCommand, Mode=OneWay}"
                  CommandParameter="{Binding ElementName=window, Mode=OneWay}" />
         </MenuItem>
         <MenuItem Header="Stats" Visibility="Collapsed">
            <MenuItem Header="Select Stats Columns..."
                  Command="{Binding ShowStatsColumnSelectCommand, Mode=OneWay}" />
            <MenuItem Header="Show Stats Panel" IsCheckable="True"
                  IsChecked="{Binding StatsPanelVisible}" />
            <MenuItem Header="Clear Columns"
                  Command="{Binding ClearStatsPanelCommand, Mode=OneWay}" />
         </MenuItem>
      </Menu>
      <Grid x:Name="LayoutRoot" Margin="5">
         <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
         </Grid.RowDefinitions>
         <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
         </Grid.ColumnDefinitions>
         <view:WellListView Grid.RowSpan="2" />
         <GroupBox Header="Well Properties" VerticalAlignment="Top" Grid.Column="1">
            <Grid>
               <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="*" />
                  <ColumnDefinition Width="Auto" />
               </Grid.ColumnDefinitions>
               <Grid.RowDefinitions>
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
                  <RowDefinition Height="Auto" />
               </Grid.RowDefinitions>
               <TextBlock Text="Title" TextTrimming="CharacterEllipsis" Padding="3"
                     Margin="3" Height="22" VerticalAlignment="Top" />
               <TextBox Height="23" TextWrapping="Wrap" VerticalAlignment="Top"
                     Padding="3" Margin="3" Text="{Binding SelectedWell.Title}"
                     Grid.Column="1" Grid.ColumnSpan="2" />
               <TextBlock Text="Time Datum (s)" TextTrimming="CharacterEllipsis"
                     Padding="3" Margin="3" Height="23" VerticalAlignment="Top"
                     Grid.Row="1" />
               <TextBox TextWrapping="Wrap" Padding="3" Margin="3"
                     Text="{Binding SelectedWell.TimeDatum}" Grid.Column="1" Height="23"
                     VerticalAlignment="Top" Grid.Row="1" Grid.ColumnSpan="2" />
               <TextBlock Text="KB (feet)" TextTrimming="CharacterEllipsis" Padding="3"
                     Margin="3" Height="23" VerticalAlignment="Top" Grid.Row="2" />
               <TextBox TextWrapping="Wrap" VerticalAlignment="Top" Padding="3" Margin="3"
                     Text="{Binding SelectedWell.KB}" Grid.Column="1" Height="23"
                     Grid.Row="2" Grid.ColumnSpan="2" />
               <TextBlock Text="Sampling Rate (ms)" TextTrimming="CharacterEllipsis"
                     Padding="3" Margin="3" Height="23" Grid.Row="3" />
               <TextBox TextWrapping="Wrap" Padding="3" Margin="3"
                     Text="{Binding SelectedWell.SampleRate}" Grid.Column="1" Height="23"
                     Grid.Row="3" Grid.ColumnSpan="2" />
               <TextBlock Text="Seismic Datum (ft)" TextTrimming="CharacterEllipsis"
                     Padding="3" Margin="3" Height="23" Grid.Row="4" />
               <TextBox TextWrapping="Wrap" Padding="3" Margin="3"
                     Text="{Binding SelectedWell.SeismicDatum, TargetNullValue=double.NaN}"
                     Grid.Column="1" Height="23" Grid.Row="4" />
               <Button Content="Use For All Wells" Grid.Column="2" Margin="3" Grid.Row="4"
                     Command="{Binding UseForAllCommand, Mode=OneWay}"
                     CommandParameter="{DynamicResource DatumString}" />
               <TextBlock Text="Seismic Velocity (ft/s)" TextTrimming="CharacterEllipsis"
                     Padding="3" Margin="3" Height="23" Grid.Row="5" />
               <TextBox TextWrapping="Wrap" Padding="3" Margin="3"
                     Text="{Binding SelectedWell.SeismicVelocity, TargetNullValue=double.NaN}"
                     Grid.Column="1" Height="23" Grid.Row="5" />
               <Button Content="Use For All Wells" Grid.Column="2" Margin="3" Grid.Row="5"
                     Command="{Binding UseForAllCommand, Mode=OneWay}"
                     CommandParameter="{DynamicResource VelocityString}" />
            </Grid>
         </GroupBox>
         <TabControl Grid.Column="1" Grid.Row="1" TabStripPlacement="Bottom" Margin="5">
            <TabItem Header="Log Data">
               <DataGrid AutoGenerateColumns="False"
                     ItemsSource="{Binding SelectedWell.LogData, Mode=OneWay}"
                     AlternatingRowBackground="#FFDEF9FF" CanUserDeleteRows="False"
                     CanUserReorderColumns="True" CanUserSortColumns="True"
                     FrozenColumnCount="1" Margin="0" IsReadOnly="True"
                     comutil:MultiSelect.IsEnabled="True" ColumnWidth="Auto">
                  <DataGrid.Columns>
                     <DataGridTextColumn Binding="{Binding Time, StringFormat=G5}"
                           Header="Time (ms)">
                     </DataGridTextColumn>
                     <DataGridTextColumn Binding="{Binding Depth, StringFormat=G5}"
                           Header="Depth (feet)">
                     </DataGridTextColumn>
                     <DataGridTextColumn Binding="{Binding DT1, StringFormat=G5}"
                           Header="DT1 (us/f)">
                     </DataGridTextColumn>
                     <DataGridTextColumn Binding="{Binding RhoB1, StringFormat=G5}"
                           Header="RhoB1 (g/cm^3)">
                     </DataGridTextColumn>
                     <DataGridTextColumn Binding="{Binding Velocity, StringFormat=G5}"
                           Header="Velocity (ft/s)">
                     </DataGridTextColumn>
                  </DataGrid.Columns>
               </DataGrid>
            </TabItem>
            <TabItem Header="Formation Tops">
               <DataGrid AutoGenerateColumns="False"
                     ItemsSource="{Binding SelectedWell.TopsData.Formations, Mode=OneWay}"
                     AlternatingRowBackground="#FFDEF9FF" CanUserDeleteRows="False"
                     CanUserReorderColumns="True" CanUserSortColumns="True"
                     FrozenColumnCount="1" Margin="0" IsReadOnly="True"
                     comutil:MultiSelect.IsEnabled="True" ColumnWidth="Auto">
                  <DataGrid.Columns>
                     <DataGridTextColumn Binding="{Binding Name, StringFormat=G5}"
                           Header="Name">
                     </DataGridTextColumn>
                     <DataGridTextColumn Binding="{Binding Depth, StringFormat=G5}"
                           Header="Depth (feet)">
                     </DataGridTextColumn>
                     <DataGridTextColumn Binding="{Binding Time, StringFormat=G5}"
                           Header="Time (ms)">
                     </DataGridTextColumn>
                  </DataGrid.Columns>
               </DataGrid>
            </TabItem>
         </TabControl>
      </Grid>
   </DockPanel>
</Window>
